home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / ftp4w26a / ftp4w.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-10  |  13.5 KB  |  291 lines

  1.  
  2. /* *************************************************************** */
  3. /*                                                                 */
  4. /*                                                                 */
  5. /*                                                                 */
  6. /*    FTP4W.DLL  (Version 2.6)                                     */
  7. /*                                                                 */
  8. /*                                                                 */
  9. /*                                   By Ph. Jounin (SNCF 71-26-12) */
  10. /*                                        Internet ark@ifh.sncf.fr */
  11. /*                                            Copyright SNCF 94-96 */
  12. /* *************************************************************** */
  13.  
  14.  
  15. #ifndef _FTP4W_API_
  16.  
  17. #include <winsock.h>
  18.  
  19. #ifdef __cplusplus  
  20. extern "C" {            /* Assume C declarations for C++ */   
  21. #endif  /* __cplusplus */   
  22.  
  23. #ifdef DEBUG
  24. #  define  FTP_DATABUFFER  256                 /* slown down the transfer */
  25. #else
  26. #  define  FTP_DATABUFFER  4096 /* a good value for X25/Ethernet/Token Ring */
  27. #endif
  28.  
  29.  
  30.  
  31. /* ----------------------------------------------------------- */
  32.  
  33. /* ASCII or binary transfer */
  34. #define   TYPE_A        'A'
  35. #define   TYPE_I        'I'
  36. #define   TYPE_L8       'L'
  37. #define   TYPE_DEFAULT   0
  38.                           
  39. /* actions requested by user */
  40. #define   FTP4W_STORE_ON_SERVER   65
  41. #define   FTP4W_APPEND_ON_SERVER  87
  42. #define   FTP4W_GET_FROM_SERVER   223
  43.  
  44. /* Firewall Types */
  45. #define   FTP4W_FWSITE             100
  46. #define   FTP4W_FWPROXY            103
  47. #define   FTP4W_FWUSERWITHLOGON    106
  48. #define   FTP4W_FWUSERNOLOGON      109
  49.  
  50.                           
  51. /* ----------------------------------------------------------- */
  52. /*              Return codes of FTP functions                  */
  53. /* ----------------------------------------------------------- */
  54. /* success */
  55. #define  FTPERR_OK                    0 /* succesful function                */
  56. /* OK but waits for further parameters */
  57. #define  FTPERR_ENTERPASSWORD         1 /* userid need a password            */
  58. #define  FTPERR_ENTERACCOUNT          2 /* user/pass OK but account required */
  59. #define  FTPERR_ACCOUNTNEEDED         2 /* user/pass OK but account required */
  60. #define  FTPERR_RESTARTOK             3 /* Restart command successful        */
  61. #define  FTPERR_ENDOFDATA             4  /* server has closed the data-conn   */
  62. #define  FTPERR_CANCELBYUSER         -1 /* Transfer aborted by user FtpAbort */
  63. /* user's or programmer's Errors  */
  64. #define  FTPERR_INVALIDPARAMETER   1000 /* Error in parameters               */
  65. #define  FTPERR_SESSIONUSED        1001 /* User has already a FTP session    */
  66. #define  FTPERR_NOTINITIALIZED     1002 /* FtpInit has not been call         */
  67. #define  FTPERR_NOTCONNECTED       1003 /* User is not connected to a server */
  68. #define  FTPERR_CANTOPENFILE       1004 /* can not open specified file       */
  69. #define  FTPERR_CANTOPENLOCALFILE  FTPERR_CANTOPENFILE
  70. #define  FTPERR_CANTWRITE          1005 /* can't write into file (disk full?)*/
  71. #define  FTPERR_NOACTIVESESSION    1006 /* FtpRelease without FtpInit        */
  72. #define  FTPERR_STILLCONNECTED     1007 /* FtpRelease without any Close      */
  73. #define  FTPERR_SERVERCANTEXECUTE  1008 /* file action not taken             */
  74. #define  FTPERR_LOGINREFUSED       1009 /* Server rejects usrid/passwd       */
  75. #define  FTPERR_NOREMOTEFILE       1010 /* server can not open file          */
  76. #define  FTPERR_TRANSFERREFUSED    1011 /* Host refused the transfer         */
  77. #define  FTPERR_WINSOCKNOTUSABLE   1012 /* A winsock.DLL ver 1.1 is required */
  78. #define  FTPERR_CANTCLOSE          1013 /* Close failed (cmd is in progress) */
  79. #define  FTPERR_FILELOCKED         1014 /* temporary error during FtpDelete  */
  80. #define  FTPERR_FWLOGINREFUSED     1015 /* Firewallrejects usrid/passwd      */
  81. #define  FTPERR_ASYNCMODE          1016 /* FtpMGet only in synchronous mode  */
  82. /* TCP errors */
  83. #define  FTPERR_UNKNOWNHOST        2001 /* can not resolve host adress       */
  84. #define  FTPERR_NOREPLY            2002 /* host does not send an answer      */
  85. #define  FTPERR_CANTCONNECT        2003 /* Error during connection           */
  86. #define  FTPERR_CONNECTREJECTED    2004 /* host has no FTP server            */
  87. #define  FTPERR_SENDREFUSED        2005 /* can't send data (network down)    */
  88. #define  FTPERR_DATACONNECTION     2006 /* connection on data-port failed    */
  89. #define  FTPERR_TIMEOUT            2007 /* timeout occured                   */
  90. #define  FTPERR_FWCANTCONNECT      2008 /* Error during connection with FW   */
  91. #define  FTPERR_FWCONNECTREJECTED  2009 /* Firewall has no FTP server        */
  92. /* FTP server errors */
  93. #define  FTPERR_UNEXPECTEDANSWER   3001  /* answer was not expected          */
  94. #define  FTPERR_CANNOTCHANGETYPE   3002  /* host rejects the TYPE command    */
  95. #define  FTPERR_CMDNOTIMPLEMENTED  3003  /* host recognize but can't exec cmd*/
  96. #define  FTPERR_PWDBADFMT          3004  /* PWD cmd OK, but answer has no "  */
  97. #define  FTPERR_PASVCMDNOTIMPL     3005  /* Server don't support passive mode*/
  98. /* Resource errors */
  99. #define  FTPERR_CANTCREATEWINDOW   5002  /* Insufficent free resources       */
  100. #define  FTPERR_INSMEMORY          5003  /* Insuffisent Heap memory          */
  101. #define  FTPERR_CANTCREATESOCKET   5004  /* no more socket                   */
  102. #define  FTPERR_CANTBINDSOCKET     5005  /* bind is not succesful            */
  103. #define  FTPERR_SYSTUNKNOWN        5006  /* host system not in the list      */
  104.  
  105. /* ----------------------------------------------------------- */
  106. struct S_FtpData
  107. {
  108.    SOCKET   ctrl_socket;    /* control stream       init INVALID_SOCKET */
  109.    SOCKET   data_socket;    /* data stream          init INVALID_SOCKET */
  110.    char     cType;          /* type (ASCII/binary)  init TYPE_A         */
  111.    BOOL     bVerbose;       /* verbose mode         init FALSE          */ 
  112.    BOOL     bPassif;        /* VRAI -> mode passif                      */ 
  113.    unsigned short nPort;    /* connexion Port       init FTP_DEFPORT    */
  114.    unsigned nTimeOut;       /* TimeOut in seconds   init FTP_DEFTIMEOUT */
  115.    HFILE    hLogFile;       /* Log file                                 */ 
  116.    char     szInBuf [2048]; /* incoming Buffer                          */
  117.    struct sockaddr_in saSockAddr;   /* not used anymore */
  118.    struct sockaddr_in saAcceptAddr; /* not used anymore */
  119. }; /* struct S_FtpData */
  120.  
  121.  
  122. struct S_FileTrf 
  123. {
  124.    HFILE    hf;         /* handle of the file which is being transfered */
  125.    unsigned nCount;     /* number of writes/reads made on a file        */
  126.    unsigned nAsyncAlone;/* pause each N frame in Async mode  (Def 40)   */
  127.    unsigned nAsyncMulti;/* Idem but more than one FTP sssion (Def 10)   */
  128.    unsigned nDelay;     /* time of the pause in milliseconds            */
  129.    BOOL     bAborted;   /* data transfer has been canceled              */
  130.    char     szBuf[FTP_DATABUFFER]; /* Data buffer                       */
  131.    BOOL     bNotify;    /* application receives a msg each data packet  */
  132.    BOOL     bAsyncMode; /* synchronous or asynchronous Mode             */
  133.    LONG     lPos;       /* Bytes transfered                             */
  134.    LONG     lTotal;     /* bytes to be transfered                       */
  135. }; /* struct S_FileTrf */
  136.  
  137. struct S_Msg
  138. {
  139.    HWND          hParentWnd;        /* window which the msg is to be passed   */
  140.    UINT          nCompletedMessage; /* msg to be sent at end of the function  */
  141. };  /* struct S_Msg */
  142.  
  143.  
  144. struct S_Verbose
  145. {
  146.    HWND          hVerboseWnd;  /* window which the message is to be passed    */
  147.    UINT          nVerboseMsg;  /* msg to be sent each time a line is received */
  148. };
  149.  
  150. /* global structure */
  151. struct S_ProcData
  152. {  
  153.    /* task data */
  154.    HTASK      hTask;              /* Task Id                              */
  155.    HWND       hFtpWnd;            /* Handle of the internal window        */
  156.    HWND       hParentWnd;         /* handle given to the FtpInit function */
  157.    HINSTANCE  hInstance;          /* Task Instance                        */
  158.    BOOL       bRelease;           /* FtpRelease has been called           */
  159.  
  160.    /* Mesasge information */
  161.    struct S_Msg      Msg;      
  162.    struct S_Verbose  VMsg;      
  163.                                                                
  164.    /* File information */
  165.    struct S_FileTrf  File;  
  166.  
  167.    /* Ftp information */
  168.    struct S_FtpData   ftp;
  169.  
  170.    /* Linked list */
  171.    struct S_ProcData far *Next;
  172.    struct S_ProcData far *Prev;
  173. }; /* struct S_ProcData */
  174.  
  175. typedef struct S_ProcData far * LPProcData;
  176. typedef struct S_FtpData far *  LPFtpData;
  177.  
  178.  
  179.  
  180. /* **************************************************************** */
  181. /*                                                                  */
  182. /*                    P R O T O T Y P E S                           */
  183. /*                                                                  */
  184. /* **************************************************************** */
  185.  
  186. /* Utilities functions */
  187. LPProcData PASCAL FAR  FtpDataPtr (void);
  188. LPSTR PASCAL FAR  FtpBufferPtr (void);
  189. LPSTR PASCAL FAR  FtpErrorString (int Rc);
  190. int PASCAL FAR WEP (int nType);
  191. int PASCAL FAR Ftp4wVer (LPSTR szVerStr, int nStrSize);
  192.  
  193. /* change default parameters */
  194. int  PASCAL FAR FtpSetVerboseMode (BOOL bVerboseMode, HWND hVerboseWnd, UINT wMsg);
  195. long PASCAL FAR FtpBytesTransferred (void);
  196. long PASCAL FAR FtpBytesToBeTransferred(void);
  197. void PASCAL FAR FtpSetDefaultTimeOut (int nTo_in_sec);
  198. void PASCAL FAR FtpSetDefaultPort(int nDefPort);
  199. void PASCAL FAR FtpSetAsynchronousMode(void);
  200. void PASCAL FAR FtpSetSynchronousMode(void);
  201. BOOL PASCAL FAR FtpIsAsynchronousMode(void);   
  202. void PASCAL FAR FtpSetNewDelay(int x); 
  203. void PASCAL FAR FtpSetNewSlices(int x,int y) ;
  204. void PASCAL FAR FtpSetPassiveMode (BOOL bPassive);
  205. void PASCAL FAR FtpLogTo (HFILE hLogFile);
  206. /* mispelled functions - only for backwards compatibilty */
  207. long PASCAL FAR FtpBytesTransfered (void);
  208. long PASCAL FAR FtpBytesToBeTransfered(void);
  209.  
  210. /* Init functions */
  211. int PASCAL FAR FtpRelease (void);
  212. int PASCAL FAR FtpInit (HWND hParentWnd);
  213. int PASCAL FAR FtpFlush (void);
  214.  
  215. /* Connection */
  216. int PASCAL FAR FtpLogin (LPSTR szHost, LPSTR szUser, LPSTR szPasswd,
  217.                          HWND hParentWnd, UINT wMsg);
  218. int PASCAL FAR FtpOpenConnection (LPSTR szHost);
  219. int PASCAL FAR FtpCloseConnection (void);
  220. int PASCAL FAR FtpLocalClose (void);
  221.  
  222. /* authentification */
  223. int PASCAL FAR  FtpSendUserName (LPSTR szUserName);
  224. int PASCAL FAR  FtpSendPasswd (LPSTR szPasswd);
  225. int PASCAL FAR  FtpSendAccount (LPSTR szAccount);
  226.  
  227. /* commands */
  228. int PASCAL FAR FtpHelp   (LPSTR szArg, LPSTR szBuf, UINT uBufSize);
  229. int PASCAL FAR FtpDeleteFile (LPSTR szRemoteFile);
  230. int PASCAL FAR FtpRenameFile (LPSTR szFrom, LPSTR szTo);
  231. int PASCAL FAR FtpQuote  (LPSTR szCmd, LPSTR szReplyBuf, UINT uBufSize);
  232. int PASCAL FAR FtpSyst   (LPSTR FAR *szSystemStr);
  233. int PASCAL FAR FtpSetType(char cType);
  234. int PASCAL FAR FtpCWD    (LPSTR szPath);
  235. int PASCAL FAR FtpCDUP   (void);
  236. int PASCAL FAR FtpPWD    (LPSTR szBuf, UINT uBufSize);
  237. int PASCAL FAR FtpMKD    (LPSTR szPath, LPSTR szFullDir, UINT uBufSize);
  238. int PASCAL FAR FtpRMD    (LPSTR szPath);
  239.  
  240. /* file transfer */
  241. int PASCAL FAR FtpAbort (void);
  242. int PASCAL FAR FtpSendFile (LPSTR szLocal, LPSTR szRemote, char cType, 
  243.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  244. int PASCAL FAR FtpAppendToRemoteFile (LPSTR szLocal, LPSTR szRemote,char cType,
  245.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  246. int PASCAL FAR FtpRecvFile (LPSTR szRemote, LPSTR szLocal, char cType, 
  247.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  248. int PASCAL FAR FtpAppendToLocalFile (LPSTR szLocal, LPSTR szRemote,char cType,
  249.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  250. DWORD PASCAL FAR FtpGetFileSize (void);
  251. int PASCAL FAR FtpMGet (LPSTR szFilter, char cType, BOOL bNotify,
  252.                  BOOL (CALLBACK *f) (LPSTR szRemFile, LPSTR szLocalFile, int Rc) );
  253.  
  254. int PASCAL FAR FtpRestart (long lByteCount);
  255. int PASCAL FAR FtpRestartSendFile (HFILE hLocal, LPSTR szRemote, char cType, 
  256.                             BOOL bNotify, long lByteCount,
  257.                             HWND hParentWnd, UINT wMsg);
  258. int PASCAL FAR FtpRestartRecvFile (LPSTR szRemote, HFILE hLocal, char cType, 
  259.                             BOOL bNotify, long lByteCount,
  260.                             HWND hParentWnd, UINT wMsg);
  261.  
  262.  
  263. /* Directory */
  264. int PASCAL FAR FtpDir (LPSTR szDef, LPSTR szLocalFile,
  265.                        BOOL  bLongDir, HWND  hParentWnd, UINT wMsg);
  266.  
  267. /* Advanced function */
  268. int PASCAL FAR FtpOpenDataConnection (LPSTR szRemote,int nAction,char cType);
  269. int PASCAL FAR FtpRecvThroughDataConnection (LPSTR szBuf,
  270.                                             unsigned int far *lpBufSize);
  271. int PASCAL FAR FtpSendThroughDataConnection(LPSTR szBuf,unsigned int uBufSize);
  272. int PASCAL FAR FtpCloseDataConnection (void);
  273.  
  274. /* Firewall function */
  275. int PASCAL FAR FtpFirewallLogin(LPSTR szFWHost, LPSTR szFWUser, LPSTR szFWPass,
  276.                                 LPSTR szRemHost,LPSTR szRemUser,LPSTR szRemPass,
  277.                                 int nFirewallType,
  278.                                 HWND hParentWnd, UINT wMsg);
  279. int PASCAL FAR IntFtpGetAnswerCode ();
  280.  
  281.  
  282. /* _______________________________________________________________ */
  283.  
  284. #ifdef __cplusplus     
  285. }  /* End of extern "C" */   
  286. #endif /* ifdef __cplusplus */  
  287.  
  288. #define _FTP4W_API_ loaded
  289. #endif /* ifndef FTP4W_API */
  290.  
  291.